package com.wsoft.config;

import com.wsoft.handler.JobHandler;
import com.wsoft.utils.job.JobLauncher;
import com.wsoft.utils.job.JobRepository;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 定时任务配置
 * @Author z001
 * @Date 2024/10/23 13:07
 */
@Configuration
@EnableConfigurationProperties(JobConfig.class)
public class JobAutoConfiguration {

    private final JobConfig jobConfig;

    private final JobRepository jobRepository;

    private final List<JobHandler> jobInterfaceList;

    public JobAutoConfiguration(JobConfig jobConfig,
                                JobRepository jobRepository,
                                List<JobHandler> jobInterfaceList) {
        this.jobConfig = jobConfig;
        this.jobRepository = jobRepository;
        this.jobInterfaceList = jobInterfaceList;
    }

    /**
     * 定时任务启动器
     *
     * @return
     */
    @Bean
    public JobLauncher initJobLauncher() {
        return new JobLauncher(jobConfig, jobRepository, jobInterfaceList);
    }
}
